<?php
namespace App\Http\Model\Flow;

use Illuminate\Support\Facades\DB;

class ClassListPayResultHistoryModel
{
    private static $_table = 'class_list_pay_result_history';

    public static function fetchClassPayHistoryData($ids, $where, $enablePage,  $page, $limit)
    {
        if ($enablePage) {
            if ($page <= 0) {
                $page = 1;
            }
            $start = ($page - 1) * $limit;

            $classPayResult = DB::table(self::$_table)->whereIn('pfs_dw_id', $ids)->where($where)
                ->orderByDesc('push_time')
                ->offset($start)->limit($limit)->get();
        } else {
            $classPayResult = DB::table(self::$_table)->whereIn('pfs_dw_id', $ids)->where($where)
                ->orderByDesc('push_time')
                ->get();
        }

        return $classPayResult ? current($classPayResult) : [];
    }

    public static function fetchClassPayHistoryCount($ids, $where)
    {
        $cnt = DB::table(self::$_table)->whereIn('pfs_dw_id', $ids)->where($where)
            ->limit(1)->count();

        return $cnt ?: 0;
    }
}
